//
//  RIASECTableViewCell.m
//  AndCampus
//
//  Created by 史宵宵 on 2018/3/28.
//  Copyright © 2018年 史宵宵. All rights reserved.
//

#import "RIASECTableViewCell.h"
#import "GLPickerView.h"
@interface RIASECTableViewCell()
@property (nonatomic,strong) NSMutableArray *array;
@property (nonatomic,strong) NSArray *scoreArray;
@end

@implementation RIASECTableViewCell
- (NSMutableArray *)dataArray{
    if (!_array) {
        _array = [NSMutableArray array];
    }
    return _array;
}
- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}
- (void)setProfessionalTestInfo:(ProfessionalTestModel *)professionalTestInfo{
    _professionalTestInfo = professionalTestInfo;
    self.scoreArray = @[@"0分",@"1分",@"2分",@"3分",@"4分",@"5分",@"6分",@"7分",@"8分",@"9分",@"10分",@"11分",@"12分",@"13分",@"14分",@"15分",@"16分",@"17分",@"18分",@"19分",@"20分",@"21分",@"22分",@"23分",@"24分",@"25分"];
    if (strIsEmpty(professionalTestInfo.answer)) {
        self.array = [NSMutableArray arrayWithArray:@[@"0",@"0",@"0",@"0",@"0",@"0"]];
    }else{
        self.array = [NSMutableArray arrayWithArray:[professionalTestInfo.answer componentsSeparatedByString:@","]];
    }
    self.titleLabel.text = [NSString stringWithFormat:@"%ld/%ld %@(以下各分项选填的分数合计必须25分)",(long)self.num,(long)self.total, professionalTestInfo.title];
    
    self.firstButton.titleLabel.font = [UIFont fontWithName:@"IconFont" size: 16.0];
    self.secondButton.titleLabel.font = [UIFont fontWithName:@"IconFont" size: 16.0];
    self.thirdButton.titleLabel.font = [UIFont fontWithName:@"IconFont" size: 16.0];
    self.fourButton.titleLabel.font = [UIFont fontWithName:@"IconFont" size: 16.0];
    self.fiveButton.titleLabel.font = [UIFont fontWithName:@"IconFont" size: 16.0];
    self.sixButton.titleLabel.font = [UIFont fontWithName:@"IconFont" size: 16.0];
    [self.firstButton setTitle:[NSString stringWithFormat:@"%@分 \U0000e631",self.array[0]] forState:UIControlStateNormal];
    [self.secondButton setTitle:[NSString stringWithFormat:@"%@分 \U0000e631",self.array[1]] forState:UIControlStateNormal];
    [self.thirdButton setTitle:[NSString stringWithFormat:@"%@分 \U0000e631",self.array[2]] forState:UIControlStateNormal];
    [self.fourButton setTitle:[NSString stringWithFormat:@"%@分 \U0000e631",self.array[3]] forState:UIControlStateNormal];
    [self.fiveButton setTitle:[NSString stringWithFormat:@"%@分 \U0000e631",self.array[4]] forState:UIControlStateNormal];
    [self.sixButton setTitle:[NSString stringWithFormat:@"%@分 \U0000e631",self.array[5]] forState:UIControlStateNormal];
    
    self.firstButton.clipsToBounds = YES;
    self.firstButton.layer.borderColor = [UIColor blackColor].CGColor;
    self.firstButton.layer.borderWidth = 1;
    self.firstButton.layer.cornerRadius = 5;
    self.secondButton.clipsToBounds = YES;
    self.secondButton.layer.borderColor = [UIColor blackColor].CGColor;
    self.secondButton.layer.borderWidth = 1;
    self.secondButton.layer.cornerRadius = 5;
    self.thirdButton.clipsToBounds = YES;
    self.thirdButton.layer.borderColor = [UIColor blackColor].CGColor;
    self.thirdButton.layer.borderWidth = 1;
    self.thirdButton.layer.cornerRadius = 5;
    self.fourButton.clipsToBounds = YES;
    self.fourButton.layer.borderColor = [UIColor blackColor].CGColor;
    self.fourButton.layer.borderWidth = 1;
    self.fourButton.layer.cornerRadius = 5;
    self.fiveButton.clipsToBounds = YES;
    self.fiveButton.layer.borderColor = [UIColor blackColor].CGColor;
    self.fiveButton.layer.borderWidth = 1;
    self.fiveButton.layer.cornerRadius = 5;
    self.sixButton.clipsToBounds = YES;
    self.sixButton.layer.borderColor = [UIColor blackColor].CGColor;
    self.sixButton.layer.borderWidth = 1;
    self.sixButton.layer.cornerRadius = 5;

    self.firstLabel.text = [professionalTestInfo.question[0] valueForKey:@"context"];
    self.secondLabel.text = [professionalTestInfo.question[1] valueForKey:@"context"];
    self.thirdLabel.text = [professionalTestInfo.question[2] valueForKey:@"context"];
    self.fourLabel.text = [professionalTestInfo.question[3] valueForKey:@"context"];
    self.fiveLabel.text = [professionalTestInfo.question[4] valueForKey:@"context"];
    self.sixLabel.text = [professionalTestInfo.question[5] valueForKey:@"context"];
}

- (IBAction)firstSelect:(id)sender {
    UIButton *button = (UIButton *)sender;
    button.tag = 1000;
    [self selectButton:button];
}
- (IBAction)secondSelect:(id)sender {
    UIButton *button = (UIButton *)sender;
    button.tag = 1001;
    [self selectButton:button];
}
- (IBAction)thirdSelect:(id)sender {
    UIButton *button = (UIButton *)sender;
    button.tag = 1002;
    [self selectButton:button];
}
- (IBAction)fourSelect:(id)sender {
    UIButton *button = (UIButton *)sender;
    button.tag = 1003;
    [self selectButton:button];
}
- (IBAction)fiveSelect:(id)sender {
    UIButton *button = (UIButton *)sender;
    button.tag = 1004;
    [self selectButton:button];
}
- (IBAction)sixSelect:(id)sender {
    UIButton *button = (UIButton *)sender;
    button.tag = 1005;
    [self selectButton:button];
}
- (void)selectButton:(UIButton *)sender{
    NSInteger tag = sender.tag - 1000;
    GLPickerView *pickView= [[GLPickerView alloc]initDatePackerWithDataArray:self.scoreArray Response:^(NSString *title) {
        [sender setTitle:[NSString stringWithFormat:@"%@ \U0000e631",title] forState:UIControlStateNormal];
        NSInteger num = [self.scoreArray indexOfObject:title];
        [self.array replaceObjectAtIndex:tag withObject:@(num)];
        NSString *answerStr = [self.array componentsJoinedByString:@","];
        MyLog(@"-----------------%@",answerStr);
        if (self.selectRIASECTestBlock) {
            self.selectRIASECTestBlock(answerStr);
        }
    }];
    [pickView show];
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
